package com.example.administrator.zhongyichou.activity;

import android.content.Intent;
import android.view.View;
import android.widget.ExpandableListView;

import com.example.administrator.zhongyichou.adapter.MutualPublicAdapter;
import com.example.administrator.zhongyichou.base.BaseActivity;
import com.example.administrator.zhongyichou.Bean.BaseEventBean;
import com.example.administrator.zhongyichou.net.NetConfig;
import com.example.administrator.zhongyichou.net.core.RequestHttpLoader;
import com.example.administrator.zhongyichou.net.protocol.GsonBaseProtocol;
import com.example.administrator.zhongyichou.net.core.HttpLoader;
import com.example.administrator.zhongyichou.net.protocol.MutualPublicProtocol;
import com.example.administrator.zhongyichou.view.HeaderView;
import com.example.administrator.zhongyichou.R;

import java.util.HashMap;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by lichenyu on 2017/11/24.
 * 描述：互助公示
 */

public class MutualPublicityActivity extends BaseActivity<MutualPublicProtocol> implements ExpandableListView.OnChildClickListener {
    @BindView(R.id.headerview)
    HeaderView headerview;
    @BindView(R.id.listview)
    ExpandableListView listview;
    private MutualPublicAdapter adapter;
    private MutualPublicProtocol mGsonBaseProtocal;

    @Override
    protected void init() {
        ButterKnife.bind(this);
        initHead();
        //返回true，屏蔽父点击时间
        listview.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
            @Override
            public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) {
                return true;
            }
        });
        listview.setOnChildClickListener(this);
    }

    @Override
    protected void responseData(MutualPublicProtocol mGsonBaseProtocal) {
        this.mGsonBaseProtocal = mGsonBaseProtocal;
        adapter = new MutualPublicAdapter(this, mGsonBaseProtocal.getData());
        listview.setAdapter(adapter);
        //默认展开全部
        for (int i = 0; i < 3; i++) {
            if (mGsonBaseProtocal.getData().get(i) != null) {
                listview.expandGroup(i);
            }
        }
    }

    @Override
    protected HttpLoader initHttpLoader() {
        RequestHttpLoader requestHttpLoader = new RequestHttpLoader(MutualPublicProtocol.class);
        requestHttpLoader.setParams(NetConfig.HELP_LIST, new HashMap<String, String>());
        return requestHttpLoader;
    }

    @Override
    protected boolean isRequestData() {
        return true;
    }

    @Override
    protected int initContentView() {
        return R.layout.mutual_public_activity;
    }

    @Override
    public boolean onEventBus(BaseEventBean baseEventBean) {

        return false;
    }

    private void initHead() {
        headerview.setTitle("互助公示-轻松互助");
        headerview.bindOnclickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                switch (v.getId()) {
                    case HeaderView.LEFT:
                        finish();
                        break;
                }
            }
        });
    }

    @Override
    public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
        Intent intent = new Intent(this, PublicityDetailsActivity.class);
        intent.putExtra("help_id", mGsonBaseProtocal.getData().get(groupPosition).getMutual_help().get(childPosition).getHelp_id());
        startActivity(intent);
        return false;
    }
}
